package info.dani.greet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class Login
 * @author Daniel Lacasta
 * @version 1.1
 */
@WebServlet("/Login")
public class Login extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Login() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		
		
		PrintWriter output = response.getWriter();
		String login = request.getParameter("login");
		String DNI = request.getParameter("DNI");
		String Email = request.getParameter("Email");
	
		
		output.write("Your login is: " + login);;
		output.write("<br /> Your DNI is : " + DNI);
		output.write("<br />Your Email is: " + Email);;
		
		
		Pattern pattern = Pattern.compile("[a-z]{8}");
		Matcher loginChecker = pattern.matcher(login);
		
		if (loginChecker.find()){
			output.write("Ok login format correct: " + login + "<br />");			
		} else{
			output.write(" login format incorrect: " + login + "<br />");
		}
			
		
		

		
		
		
	}

}
